home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Documentation / Tech Notes & Articles / Recipes / Shell Plug-In Recipe < prev   
Encoding:
Text File  |  1995-11-08  |  4.1 KB  |  98 lines  |  [TEXT/ttxt]

  1. OpenDoc™ Recipes
  2.  
  3.  
  4. Shell Plug-In Recipe
  5. By The OpenDoc Design Team
  6. Nov 7th, 1995
  7.  
  8.  
  9. © 1993-1995  Apple Computer, Inc. All Rights Reserved.
  10. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  11. Mac and OpenDoc are trademarks of Apple Computer, Inc. 
  12.  
  13.  
  14.  
  15. Introduction
  16.  
  17. OpenDoc provides users the ability to customize their OpenDoc runtime by installing OpenDoc Shell Plug-Ins, similar to the way users can customize their MacOS™ System Folder by installing Extensions (INITs).  An OpenDoc Shell Plug-In is simply a CFM shared library located in the OpenDoc Shell Plug-Ins folder and that exports a symbol called ODShellPlugInInstall.  This document provides sample code for implementing a Shell Plug-In. 
  18.  
  19. Elements
  20.  
  21. 1. Create a source file with an entry point called ODShellPlugInInstall.  If using C++, be sure to type it "extern "C"" so that the right calling conventions will be used.
  22. 2. Set up your build system to produce a CFM shared library from the source file, and to have the library export the symbol "ODShellPlugInInstall".  Compile and link the library.
  23.  
  24. Installation
  25.  
  26. Once you have successfuly built the shared library, drop it into your OpenDoc Shell Plug-Ins folder.  Remember that the name of this folder, and of its containing folders, may differ on non-Roman Mac systems, but on Roman systems it's ":System Folder:Editors:OpenDoc:OpenDoc Shell Plug-Ins:".
  27.  
  28. Sample Code Overview
  29.  
  30. • ODShellPlugIn C or C++ code:
  31.  
  32. #include <types.h>
  33. #include <ODTypesB.xh>
  34. #include "ShPlugIn.h"
  35. #include <TextUtils.h>
  36.  
  37. // You probably want to #include the .xh files that define these classes,
  38. // so that, for instance, you can get the session from the draft, but all
  39. // we care about is that our simple example compile....
  40. class Environment;
  41. class ODDraft;
  42.  
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46.  
  47. OSErr ODShellPluginInstall( Environment* ev, ODDraft* draft,
  48.         ODShellPluginActionCodes* action );
  49.  
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53.  
  54. OSErr ODShellPluginInstall( Environment* ev, ODDraft* draft,
  55.         ODShellPluginActionCodes* action )
  56. {
  57.     DebugStr( "\pPlugin got called" );
  58.  
  59.     // Now tell the Shell to close the connection to our library as soon 
  60.     // as we return.
  61.     // This isn't what most plugins will want to do, but it's the right
  62.     // thing to do if you're just displaying a debugstr :-).  If you wanted
  63.     // to leave the library open, say because you'd registered an object
  64.     // in an object namespace, you'd clear the kODShellPluginCloseConnection
  65.     // bit if paranoid, or otherwise just leave *action alone.
  66.     *action |= kODShellPluginCloseConnection;
  67.  
  68.     // Return noErr if you want the Shell to continue starting up.  Any other
  69.     // error causes the Shell to abort with a dialog telling the user what
  70.     // plugin it was attempting to load when the error occurred and suggesting
  71.     // that he remove it from the plugins folder before attempting to open
  72.     // the document again.
  73.     // Note that the Shell ignores errors returned via the Environment*
  74.     // parameter.  Pass ev to OpenDoc routines that you call from here if
  75.     // they require it, but if any of them returns an error that way you'll
  76.     // have to deal with it yourself (if it needs dealing with at all.)  If the
  77.     // Shell gets noErr back from your plugin it assumes all is well and
  78.     // continues.
  79.     return noErr;
  80. }
  81.  
  82. • Building your library:
  83.  
  84. Building a CFM shared library generally requires both source files and a .exp file telling the linker what symbols/entry points to export.  My example build commands below assume a source file called "SmpPlgin.cpp" and a .exp file called "SmpPlgin.exp" that is a TEXT file consisting of one line: "ODShellPlugInInstall".  Given those two files in a folder, and MPW set with that folder as its current directory and with the MPW shell variable OpenDocInterfaces holding the path to your OpenDoc interface files (.xh files), the following commands will build a Shell Plug-in library named SamplePlugin.
  85.  
  86. SCpp        -i "{OpenDocInterfaces}" ∂
  87.         -model cfmflat SmpPlgin.cpp
  88.  
  89. ilink -xm s -model cfmflat -@export SmpPlgin.exp ∂
  90.         "{SharedLibraries}"InterfaceLib ∂
  91.             SmpPlgin.cpp.o ∂
  92.         -o SmpPlgin.seg
  93.  
  94. MakeFlat SmpPlgin.seg -o SamplePlugin
  95.  
  96. MergeFragment "SamplePlugin" -n "ODShellPluginInstall" ∂
  97.         -c -x -t m68k
  98.